package com.skillworld.webapp.model.courseservice;

import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import com.skillworld.webapp.model.course.Course;
import com.skillworld.webapp.model.course.LessonAlreadyFinishedException;
import com.skillworld.webapp.model.course.Course.Status;
import com.skillworld.webapp.model.enrollment.Enrollment;
import com.skillworld.webapp.model.enrollment.Examination;
import com.skillworld.webapp.model.enrollment.ReleasedExam;
import com.skillworld.webapp.model.enrollment.ReleasedExam.Grade;
import com.skillworld.webapp.model.lesson.Exam;
import com.skillworld.webapp.model.lesson.Lesson;
import com.skillworld.webapp.model.tutorial.Tutorial;
import com.skillworld.webapp.model.user.User;
import com.skillworld.webapp.model.util.InvalidArgumentException;
import com.skillworld.webapp.model.util.PermissionDeniedException;
import es.udc.pojo.modelutil.exceptions.InstanceNotFoundException;

public interface CourseService
{
    public List<Course> searchCourses(String query, Long dept, 
                                        Locale locale, Long author,
                                        Status status,
                                        int startIndex, int count);
    public int numberOfCourses(String query, Long dept, 
                                Locale locale, Long author,
                                Status status);
    public Course findCourse(long courseId) 
            throws InstanceNotFoundException;
    public CourseInfo viewCourse(long courseId, long userId)
            throws InstanceNotFoundException;
    public Lesson findLesson(long lessonId) 
            throws InstanceNotFoundException;
    public LessonInfo viewLesson(long lessonId, long userId)
            throws InstanceNotFoundException;
    public List<Exam> listExams(long userId, long courseId, 
                                List<Long> lessons, 
                                int startIndex, int count) 
            throws InstanceNotFoundException, PermissionDeniedException;
    public int numberOfExams(long userId, long courseId, 
                                List<Long> lessons) 
            throws InstanceNotFoundException, PermissionDeniedException;
    public void applyCourse(Long courseId, Long userId) 
            throws InstanceNotFoundException, PermissionDeniedException,
                    AlreadyAnStudentException, NoVacanciesLeftException;
    public Course createCourse(String name, String description, 
                                Locale locale, int maxStudents, 
                                long userId, long departmentId)
            throws InstanceNotFoundException, PermissionDeniedException;
    public Lesson createLesson(long courseId, long authorId, 
                                String name, String description, 
                                List<Long> tutorialsIds)
            throws InstanceNotFoundException, PermissionDeniedException;
    public void addTutorials(long userId, long lessonId, List<Long> tutorialsIds)
            throws InstanceNotFoundException, PermissionDeniedException; 
    public void removeTutorial(long userId, long lessonId,long tutorialId) 
            throws InstanceNotFoundException, PermissionDeniedException,
                    TutorialNotInLessonException;
    public Exam createExam(long userId, long lessonId, String fileURL)
            throws InstanceNotFoundException, PermissionDeniedException;
    public void finishCourse(long userId, long courseId) 
            throws InstanceNotFoundException, NotAMasterOfCourseException, 
                    CourseAlreadyEnabledException, LessonsRequiredException, 
                    LessonWithoutTutorialsException, LessonWithoutExamsException;
    
    // TODO review
	public void removeLesson(Long userId, Long lessonId) 
	        throws InstanceNotFoundException, NotAMasterOfCourseException;
	
	public void disableExam(long userId, long examId)
	        throws InstanceNotFoundException, NotAMasterOfCourseException,
	                ExamAlreadyDisabledException;
	
	public Map<Calendar,Lesson> listLessons(Long idUser) throws InstanceNotFoundException;

    public List<Enrollment> searchEnrollments(String query, 
                                        Long user, Long dept,
                                        Locale locale,
                                        Boolean finished, 
                                        int startIndex, int count);
    public int numberOfEnrollments(String query, 
                                    Long user, Long dept,
                                    Locale locale, Boolean finished);
	
	public Exam requestExam(long userId, long lessonId) 
	        throws InstanceNotFoundException, ExamAlreadyReleasedException, 
	                PermissionDeniedException, NotFinishedAllTutorials;
	public void answerExam(long userId, long lessonId, String fileURL) 
	        throws InstanceNotFoundException, PermissionDeniedException;
	public void evaluateExam(long examinationId, long masterId, 
	                            Grade grade, String commentary) 
	        throws InstanceNotFoundException, PermissionDeniedException;
	
	public List<Examination> listExaminations(long userId, long courseId, User.Role role, ReleasedExam.State state,  List<Long> lessons, int startIndex, int count) throws InstanceNotFoundException, PermissionDeniedException;
	public int numberOfExaminations(long userId, long courseId, User.Role role, ReleasedExam.State state,  List<Long> lessons) throws InstanceNotFoundException, PermissionDeniedException;
}